import { Entity, Column, ManyToOne, JoinColumn, OneToMany } from 'typeorm';
import { Stage } from 'src/modules/stage/entities/stage.entity';
import { MatchInfo } from 'src/modules/match/entities/match.entity';
import { GroupPlayerScore } from 'src/modules/group-player-score/entities/group-player-score.entity';
import { GroupStatusEnum } from 'src/common/constant/enums';
import { BaseEntity } from 'src/common/entity/BaseEntity';

@Entity('match_group')
export class Group extends BaseEntity {
  @Column()
  name: string;

  @Column()
  groupIndex: number;

  @Column()
  status: GroupStatusEnum;

  @OneToMany(
    () => GroupPlayerScore,
    (groupPlayerScores) => groupPlayerScores.group,
  )
  groupPlayerScores: GroupPlayerScore[];

  // players: Partial<User>[];
  @ManyToOne(() => Stage, (stage) => stage.groups)
  @JoinColumn({ name: 'fk_stage_id' })
  stage: Stage;

  @Column({ name: 'fk_stage_id' })
  stageId: number;

  @OneToMany(() => MatchInfo, (matchInfo) => matchInfo.group, {
    cascade: true,
  })
  matchInfos: Partial<MatchInfo>[];
}
